<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 
      思路：终止条件 path.length==digits.length
            确定遍历集合范围   需要一个start来确定字符串
      
      */
      var letterCombinations = function (digits) {
        if (!digits.length) return []
        const res = []
        const map = { 2: 'abc', 3: 'def', 4: 'ghi', 5: 'jkl', 6: 'mno', 7: 'pqrs', 8: 'tuv', 9: 'wxyz' }
        function backTracking(path, start) {
          if (path.length == digits.length) {
            return res.push([...path])
          }
          let str = map[digits[start]]
          for (let i = 0; i < str.length; i++) {
            path.push(str[i])
            backTracking(path, start + 1)
            path.pop()
          }
        }
        backTracking([], 0)
        return res
      }
    </script>
  </body>
</html>
